package laji;

import laji.Blog1;

import javax.swing.*;
import java.awt.*;

public class BlogViewerWindow extends JFrame {
    public BlogViewerWindow(Blog1 blog) {
        setTitle("查看博客");
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        setPreferredSize(new Dimension(400, 300));
        pack();
        setLocationRelativeTo(null);

        JPanel contentPane = new JPanel();
        contentPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
        setContentPane(contentPane);
        contentPane.setLayout(new BorderLayout(0, 10));

        JLabel titleLabel = new JLabel("标题");
        contentPane.add(titleLabel, BorderLayout.NORTH);

        JLabel titleValueLabel = new JLabel(blog.getTitle());
        contentPane.add(titleValueLabel, BorderLayout.CENTER);

        JLabel contentLabel = new JLabel("内容");
        contentPane.add(contentLabel, BorderLayout.CENTER);

        JTextArea contentTextArea = new JTextArea(blog.getContent());
        contentTextArea.setEditable(false);
        JScrollPane contentScrollPane = new JScrollPane(contentTextArea);
        contentPane.add(contentScrollPane, BorderLayout.CENTER);

        JLabel authorLabel = new JLabel("作者");
        contentPane.add(authorLabel, BorderLayout.CENTER);

        JLabel authorValueLabel = new JLabel(blog.getAuthor());
        contentPane.add(authorValueLabel, BorderLayout.CENTER);

        JLabel createdAtLabel = new JLabel("创建时间");
        contentPane.add(createdAtLabel, BorderLayout.CENTER);

        JLabel createdAtValueLabel = new JLabel(blog.getCreatedAt().toString());
        contentPane.add(createdAtValueLabel, BorderLayout.CENTER);
    }
}
